#include <climits>
#include <string>
#include <vector>
#include <utility>

using namespace std;

// 78. 子集 (深搜 回溯)
// https://leetcode.cn/problems/subsets/

// 解法一：决策树按照选或者不选
class Solution {
    vector<vector<int>> ans;
    vector<int> path;
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        dfs(nums, 0);
        return ans;
    }

    void dfs(vector<int>& nums, int pos)
    {
        if (pos == nums.size())
        {
            ans.push_back(path);
            return;
        }

        // 不选
        dfs(nums, pos+1);
        
        // 选
        path.push_back(nums[pos]);
        dfs(nums, pos+1);
        path.pop_back();
    }
};

// 解法二：决策树按照每次选多少种
class Solution {
    vector<vector<int>> ans;
    vector<int> path;
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        dfs(nums, 0);
        return ans;
    }

    void dfs(vector<int>& nums, int pos)
    {
        ans.push_back(path);
        for (int i = pos; i<nums.size(); ++i)
        {
            path.push_back(nums[i]);
            dfs(nums, i+1);
            path.pop_back();
        }
    }
};